'ss_good_articles',
'ss_total_pages',
'ss_users',
- 'ss_active_users',
'ss_images',
) as $member ) {
if ( $row->$member > 2000000000 || $row->$member < 0 ) {
* - Boolean: whether to use the master DB
* - DatabaseBase: database connection to use
* @param array $options of options, may contain the following values
- * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false)
* - views Boolean: when true, do not update the number of page views (default: true)
* - activeUsers Boolean: whether to update the number of active users (default: false)
*/
$counter->views();
}
- // Update/refresh
- if ( $options['update'] ) {
- $counter->update();
- } else {
- $counter->refresh();
- }
+ $counter->refresh();
// Count active users if need be
if ( $options['activeUsers'] ) {
}
/**
- * Update the current row with the selected values
- */
- public function update() {
- list( $values, $conds ) = $this->getDbParams();
- $dbw = wfGetDB( DB_MASTER );
- $dbw->update( 'site_stats', $values, $conds, __METHOD__ );
- }
-
- /**
- * Refresh site_stats. Erase the current record and save all
- * the new values.
+ * Refresh site_stats.
*/
- public function refresh() {
- list( $values, $conds, $views ) = $this->getDbParams();
- $dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'site_stats', $conds, __METHOD__ );
- $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ );
- }
-
- /**
- * Return three arrays of params for the db queries
- * @return Array
- */
- private function getDbParams() {
+ protected function refresh() {
$values = array(
+ 'ss_row_id' => 1,
'ss_total_edits' => $this->mEdits,
'ss_good_articles' => $this->mArticles,
'ss_total_pages' => $this->mPages,
'ss_users' => $this->mUsers,
- 'ss_images' => $this->mFiles
+ 'ss_images' => $this->mFiles,
+ ) + (
+ $this->mViews ? array( 'ss_total_views' => $this->mViews ) : array()
);
- $conds = array( 'ss_row_id' => 1 );
- $views = array( 'ss_total_views' => $this->mViews );
- return array( $values, $conds, $views );
+
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->upsert( 'site_stats', $values, array( 'ss_row_id' ), $values, __METHOD__ );
}
}